package serverComponent;

import java.util.ArrayList;
import java.util.List;

//This class contains information about an active subscription for a user
public class SubscriptionDetails
{
	private List<String> subscribedResourceList;
	private String subscriptionID;
	private boolean subscribedWithBareJID;
	
	public SubscriptionDetails()
	{
		subscribedWithBareJID = false;
		subscribedResourceList = new ArrayList<String>();
		subscriptionID = null;
	}

	public void addResource( String resource ) {
		if( !isResourceSubscribed( resource ))
			subscribedResourceList.add( resource );
	}
	public void removeResource( String removingResource )
	{
		if( !isResourceSubscribed( removingResource ))
			return ;
		
		subscribedResourceList.remove( removingResource );
	}
	public boolean isResourceSubscribed( String resource )
	{
		if( subscribedResourceList.isEmpty())
			return false;
		
		for( String subscribedResource : subscribedResourceList )
			if( subscribedResource.compareTo( resource ) == 0 )
				return true;
		
		return false;
	}
	public boolean areResourcesSubscribed() {
		return !subscribedResourceList.isEmpty();
	}
	public int getResourceSize() {
		return subscribedResourceList.size();
	}
	
	public String getSubscriptionID() {
		return subscriptionID;
	}
	public void setSubscriptionID( String subscriptionID ) {
		this.subscriptionID = subscriptionID;
	}
	
	public boolean isBareJIDSubscribed() {
		return subscribedWithBareJID;
	}
	public void setSubscribedWithBareJID( boolean value ) {
		subscribedWithBareJID = value;
	}
}
